package com.stylefeng.guns.modular.system.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.IndustryRank;
import com.stylefeng.guns.modular.system.service.IIndustryRankService;
import com.stylefeng.guns.modular.system.warpper.IndustryRankWarpper;

/**
 * 行业资金统计控制器
 *
 * @author fengshuonan
 * @Date 2018-06-29 13:40:58
 */
@Controller
@RequestMapping("/industryRank")
public class IndustryRankController extends BaseController {

    private String PREFIX = "/system/industryRank/";

    @Autowired
    private IIndustryRankService industryRankService;

    /**
     * 跳转到行业资金统计首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "industryRank.html";
    }

    /**
     * 跳转到添加行业资金统计
     */
    @RequestMapping("/industryRank_add")
    public String industryRankAdd() {
        return PREFIX + "industryRank_add.html";
    }

    /**
     * 跳转到修改行业资金统计
     */
    @RequestMapping("/industryRank_update/{industryRankId}")
    public String industryRankUpdate(@PathVariable Integer industryRankId, Model model) {
        IndustryRank industryRank = industryRankService.selectById(industryRankId);
        model.addAttribute("item",industryRank);
        LogObjectHolder.me().set(industryRank);
        return PREFIX + "industryRank_edit.html";
    }

    /**
     * 获取行业资金统计列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String date) {
    	Page<IndustryRank> page = new PageFactory<IndustryRank>().defaultPage();
    	List<Map<String, Object>> branks = industryRankService.selectMapsByDate(date,page);
    	page.setRecords((List<IndustryRank>) new IndustryRankWarpper(branks).warp());
    	 return super.packForBT(page);
    }

    /**
     * 新增行业资金统计
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(IndustryRank industryRank) {
        industryRankService.insert(industryRank);
        return SUCCESS_TIP;
    }

    /**
     * 删除行业资金统计
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer industryRankId) {
        industryRankService.deleteById(industryRankId);
        return SUCCESS_TIP;
    }

    /**
     * 修改行业资金统计
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(IndustryRank industryRank) {
        industryRankService.updateById(industryRank);
        return SUCCESS_TIP;
    }

    /**
     * 行业资金统计详情
     */
    @RequestMapping(value = "/detail/{industryRankId}")
    @ResponseBody
    public Object detail(@PathVariable("industryRankId") Integer industryRankId) {
        return industryRankService.selectById(industryRankId);
    }
}
